﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Annotations;
using System.Windows.Input;
using SnakeGame.Views;
using SnakeGame.Helpers;

namespace SnakeGame.ViewModels
{
    class JudgePageViewModel : NotifyPropertyChanged
    {
        private QuestionFrame _qFrame;
        public ICommand CorrectCommand { get; set; }
        public ICommand WrongCommand { get; set; }
        private int _win;
        public int Win { get { return _win; } set { _win = value; OnPropertyChanged("Win"); } }
        public int _lose;
        public int Lose { get { return _lose; } set { _lose = value; OnPropertyChanged("Lose"); } }
        
        public bool IsWin { get; set; }

        public JudgePageViewModel()
        {
            CorrectCommand = new RelayCommand(OnCorrectCommand);
            WrongCommand = new RelayCommand(OnWrongCommand);
        }

        protected void GoToAnswerPage()
        {
            AnswerPage aPage = new AnswerPage();
            aPage.Initialize(_qFrame, IsWin);
            _qFrame.Navigate(aPage);
        }


        private void OnWrongCommand(object obj)
        {
            PlayMusic("wrong.wav");
            IsWin = false;
            GoToAnswerPage();
        }


        private void OnCorrectCommand(object obj)
        {
            PlayMusic("correct.mp3");
            IsWin = true;
            GoToAnswerPage();
        }

        private void PlayMusic(string input)
        {
            MyMediaPlayer my = new MyMediaPlayer();
            my.Open(new Uri(input, UriKind.Relative));
            my.Play();
        }

        public void Initialize(QuestionFrame qf)
        {
            _qFrame = qf;
            Win = qf.QuestionItem.Win;
            Lose = qf.QuestionItem.Lose;
        }

    }
}
